<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * Smarty {restaurant_type_2} function plugin
 * @param array|null $params
 * @param Smarty $smarty
 */
function smarty_function_restaurant_type_2($params, $smarty) {
    if (!isset($params)) {
        return ;
    }

    if (isset($params['limit'])) {
        $limit = $params['limit'];
    } else {
        $limit = 4;
    }

    $filters = array('limit' => $limit);
    $smarty->CI->load->model('restaurant/restaurant_model');
    $data = $smarty->CI->restaurant_model->get_restaurants($filters);
    if (!$data) {
        return '';
    }

    $ci =& get_instance();
    $ci->load->helper('text');

    $html = '';
    foreach ($data as $item) {
        $intro = word_limiter($item['introtext'], 20);
        $html .= "<div class='items' style='height:320px;'>
                    <div class='items-photo'>
                        <a href='{$item[link]}' title='{$item[name]}'>
                        <img src='{$item[image1]}' alt='{$item[name]}' title='{$item[name]}' height='225'>
                        </a>
                    </div>
                    <div class='items-name' style='text-overflow:initial;white-space:normal; text-transform:initial'>
                        <h3>
                        <a href='{$item[link]}' title='{$item[name]}'> {$item[name]} </a>
                        </h3>
                    </div>
                    <div class='items-address' style='text-overflow:initial;white-space:normal'>
                         {$intro}
                    </div>
                </div>";
    }
    return $html;
}
